home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / AMOSList / AMOSLIST / text0186.txt < prev    next >
Encoding:
Text File  |  1998-04-01  |  3.5 KB  |  140 lines

  1. On Wednesday 18-Mar-98 at 13:08:17, a nutter named Jonas Thorell
  2. had wet pants when they typed about `Re: Textfile parsing'.
  3.  
  4. >Thanks for the example. It doesn't quite work but I'll see if I can work out
  5. >what's going on. When I enter s:startup-sequence as input-file I just get the
  6. >first line of it for some reason.
  7.  
  8. Ooops!  I made a slight error in the code. Well, I was typing it up as
  9. an example. Anyway, here is what it should be like. Hope this helps...
  10.  
  11. <SNIP>
  12. '
  13. ' ***************************************
  14. '
  15. ' Load and process a text file easily :) 
  16. ' bY Andy Gibson 
  17. '
  18. ' I hope this helps you out Jonas....
  19. ' Sorry about the last one! This one's
  20. ' fine though :-)
  21. '
  22. ' ***************************************
  23. '
  24. ' Depending on the size of your file, you may need to UP this value... 
  25. Set Buffer 40
  26. '
  27. ' LINES must be global here... 
  28. Global TXT$,LINES
  29. '
  30. ' Enter your text file's full path here... 
  31. Proc _LOAD_TXT["hd2:text/Letter.asc"]
  32. '
  33. '
  34. ' Now we can use a Dim with the correct amount of lines to hold
  35. ' each line in there...
  36. Dim TXT$(LINES)
  37. Global TXT$()
  38. '
  39. ' Simply sort the lines into the Global Dim here...
  40. Proc _SORT_FILE
  41. '
  42. '
  43. ' Now you can easily read any line of the text held in the array 
  44. ' TXT$().
  45. '
  46. ' eg. Print first 10 lines of text file... 
  47. For _DISPLAY=0 To 10
  48. Print TXT$(_DISPLAY)
  49. Next _DISPLAY
  50. Edit 
  51. '
  52. '
  53. '
  54. ' Procedure are here...
  55. '
  56. Procedure _LOAD_TXT[TXT$]
  57.    '
  58.    ' This Proc will work out how many lines are in your file. 
  59.    ' Checks for normal Chr$(10) RETURN code. You could alter
  60.    ' it to Chr$(13) for PC text files if need be....
  61.    '
  62.    ' Amcaf only.... (no need to use Open in etc...) 
  63.    ' Dload TXT$,17  
  64.    '
  65.    '
  66.    ' Amos normal way... 
  67.    Open In 1,TXT$
  68.    L=Lof(1) : Close 1
  69.    Reserve As Data 7,L
  70.    Bload TXT$,7
  71.    '
  72.    '
  73.    ' Read Lines...
  74.    POS=Start(7) : LINES=0
  75.    '
  76.    Do 
  77.       Exit If POS>=Bank End(7)
  78.       LINE=Hunt(POS To Bank End(7),Chr$(10))
  79.       '
  80.       ' Wanna see the text...
  81.    '   A$=Peek$(POS,POS-LINE,Chr$(10))
  82.    '   Print A$ 
  83.       '
  84.       Exit If LINE=Bank End(7) or LINE=0
  85.       POS=LINE+1
  86.       Inc LINES
  87.    Loop 
  88.    '
  89.    ' One other point to note, the Bank End command is not an normal 
  90.    ' Amos Pro one! And I can't remember which Ext I have installed
  91.    ' which uses it! If this code doesn't funtion properly in your 
  92.    ' interpreter, simply change the Bank End commands to summat 
  93.    ' more suitable like Start(bnk)+start(bnk) to Length(bnk)
  94.    '
  95. End Proc
  96. Procedure _SORT_FILE
  97.    '
  98.    ' Hold each line of text in the array...easy or what?
  99.    '
  100.    POS=Start(7)
  101.    '
  102.    For I=0 To LINES
  103.       A$=Peek$(POS,Bank End(7),Chr$(10))
  104.       If A$>""
  105.          TXT$(I)=Peek$(POS,Bank End(7),Chr$(10))
  106.          Add POS,Len(TXT$(I))+1
  107.       Else 
  108.          Inc POS
  109.       End If 
  110.    Next I
  111.    '
  112.    ' No more need to hold the file in a mem bank, so erase it...
  113.    '
  114.    Erase 7
  115.    '
  116. End Proc
  117. '
  118. <SNIP>
  119.  
  120. Once again, sorry for the slight mix-up with the last one sent! 
  121.  
  122. If you need further help, feel free to email me. I'll do my best.
  123.  
  124. Tarra. Andy Gibson
  125.  
  126.  
  127. -- 
  128. *****************************************************************
  129. *_______/\_____/\_______/\_____/\                               *
  130. *\       /\  ___/\       /\  ___/ Andy Gibson <---------------- *
  131. * \_/\  / /\/|  _ \_/\  /  \/ \   ----------> aka SKiDZ/Area 51 *
  132. * / _/ / /   |_| // _/ /  __\  \                                *
  133. * \// /  \___   / \// /  /__   /    andy@agasinc.demon.co.uk    *
  134. *  /_/       \_/   /_/      \_/      <-=-=-=-=-=-=-=-=-=->      *
  135. *         pRODUCTiONS 9T8                                       *
  136. *****************************************************************
  137.  
  138.  
  139.  
  140.